home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PCMania 39
/
PCMania CD39_2.iso
/
pcmania
/
treal39
/
vect.h
< prev
Wrap
C/C++ Source or Header
|
1993-08-01
|
2KB
|
90 lines
#ifndef __VECTOR_H
#define __VECTOR_H
#include <math.h>
#include <fstream.h>
#define DOT %
#define CROSS *
class Vector {
public:
static char delim;
static void set_delim (char new_delim) { delim = new_delim; }
float x, y, z;
Vector() {x = 0.0; y = 0.0; z = 0.0;}
Vector (float NewX, float NewY, float NewZ)
{x = NewX; y = NewY; z = NewZ;}
friend Vector operator+ (Vector v1, Vector v2);
friend Vector operator- (Vector v1, Vector v2);
friend Vector operator- (Vector v);
friend Vector operator* (Vector v1, Vector v2);
friend float operator% (Vector v1, Vector v2);
friend Vector operator* (float N, Vector v);
friend Vector operator* (Vector v, float N);
friend Vector operator/ (Vector v, float N);
friend Vector min (const Vector &v1, const Vector &v2);
friend Vector max (const Vector &v1, const Vector &v2);
friend float mag (Vector v);
friend float angle (const Vector &v1, const Vector &v2);
friend ostream& operator<< (ostream& f, const Vector& v);
};
inline float mag (Vector v)
{
return (sqrt(v.x*v.x + v.y*v.y + v.z*v.z));
}
inline Vector operator+ (Vector v1, Vector v2)
{
return Vector (v1.x + v2.x, v1.y + v2.y, v1.z + v2.z);
}
inline Vector operator- (Vector v1, Vector v2)
{
return Vector (v1.x - v2.x, v1.y - v2.y, v1.z - v2.z);
}
inline Vector operator- (Vector v)
{
return Vector (-v.x, -v.y, -v.z);
}
inline Vector operator* (Vector v1, Vector v2)
{
Vector Temp;
Temp.x = (v1.z * v2.y) - (v1.y * v2.z);
Temp.y = (v1.x * v2.z) - (v1.z * v2.x);
Temp.z = (v1.y * v2.x) - (v1.x * v2.y);
return Temp;
}
inline float operator% (Vector v1, Vector v2)
{
return (v1.x*v2.x) + (v1.y*v2.y) + (v1.z*v2.z);
}
inline Vector operator* (float N, Vector v)
{
return Vector (N*v.x, N*v.y, N*v.z);
}
inline Vector operator* (Vector v, float N)
{
return Vector (N*v.x, N*v.y, N*v.z);
}
inline Vector operator/ (Vector v, float N)
{
return Vector (v.x/N, v.y/N, v.z/N);
}
#endif